package com.roast.pages;

import com.roast.domain.UserData;
import com.roast.services.my.MyServicesFacade;
import com.roast.services.messges.GetSystemMessageFacade;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.InjectService;

public class Singup {

    @InjectService("MyServicesFacade")
    MyServicesFacade myServices;

    @InjectService("GetSystemMessageFacade")
    GetSystemMessageFacade getSystemMessage;
    @Property
    String email;

    @Property
    String nickname;

    @Property
    String password;

    @Property
    String systemMessage;

    @OnEvent(value = "submit", component = "registration")
    Object onFormSubmit() {
        UserData user = new UserData();
        user.setEmail(email);
        user.setPassword(password);
        user.setNickname(nickname);

        int signal = myServices.singup(user);
        systemMessage = getSystemMessage.singup(signal);

        return null;
    }

    void onActivate(String systemMessage) {
        this.systemMessage = systemMessage;
    }

    String onPassivate() {
        return systemMessage;
    }
}
